from flask import Flask,request
from flask import render_template
from reserch import reserch4letters


app = Flask(__name__)

#1.路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
#1.1 url:相对于：http://127.0.0.1：5000的相对路径
#1.2 methods:[GET] [POST]
#2.视图函数:
#2.1 函数过程决定了你操作的方法（实现的功能），例如 if elief else for while...
#2.2 return:可以是txt文本，html文件(模板渲染)，可以是jsdn文件

#【GET】
@app.route('/',methods=['GET'])
def hello():  # put application's code here
    return render_template('hello.html')

@app.route('/index',methods=['GET'])
def index():  # put application's code here
    return render_template('word_index.html')

@app.route('/shopping_home',methods=['GET'])
def shopping_home():  # put application's code here
    return render_template('shopping_cart.html')

@app.route('/drink',methods=['GET'])
def drink():  # put application's code here
    return render_template('drink.html')

@app.route('/index2',methods=['GET'])
def index2():  # put application's code here
    return render_template('name_index.html')


#[POST]实现用户输入,点击提交，将数据提交到/result

@app.route('/shop_result',methods=['POST'])
def shop_result():

    py_iphone = request.form['iphone']
    py_denglu = py_iphone

    return render_template('shop_result.html',
                           dengji = py_denglu)

@app.route('/name_result',methods=['POST','GET'])
def name_result():
    # 接收数据：request.form[HTML-参数名称]
    # 1. 名字的全称（完整的应用）：用户输入数据--->后端接收数据--->后端处理数据--->返回到HTML页面
    # 2. 元音字母查询（第二个功能）
    # 3. 自选：购物车 或者 课程表
    py_firstname = request.form['firstname']
    py_lastname = request.form['lastname']
    py_fullname = py_firstname.title()+' '+py_lastname.title()
    return render_template('name_result.html',
                           fullname = py_fullname)

@app.route('/drink_result',methods=['POST'])
def drink_result():
    product_lists = [
        ("葡萄益菌多", "￥15"),
        ("草莓益菌多", "￥15"),
        ("西柚益菌多", "￥15"),
        ("蜜桃益菌多", "￥15"),
        ("芒果益菌多", "￥15"),
        ("柠檬益菌多", "￥15"),
        ("鲜橙益菌多", "￥15"),
        ("火龙果益菌多", "￥15"),
        ("百香果益菌多", "￥15")
    ]

    return render_template('drink_result.html',product_lists=product_lists)

@app.route('/last', methods=['POST', 'GET'])
def last():

    name = request.form.get("name")
    tel = request.form.get('tel')
    add = request.form.get("add")
    lst = request.form.getlist('list')
    lst_str = "，".join(lst)
    return render_template('last.html',
                           name=name,
                           tel=tel,
                           add=add,
                           lst_name=lst_str)

@app.route('/word_result',methods=['POST','GET'])
def word_result():
    py_word = request.form['word']
    py_vowels = request.form['vowels']
    py_found = reserch4letters(py_vowels,py_word)
    return render_template('word_result.html',
                           found = py_found)


if __name__ == '__main__':
    app.run()